<?php

class fvFilterFilter implements iFilter {
    
    public function __construct() {
        
    }
    
    public function execute() {
        $currentUrl = fvRequest::getInstance()->getRequestParameter('requestURL');
        
        $filterArray = fvRequest::getInstance()->getRequestParameter('filter');
        
        if (!is_array($filterArray)) {
            if (!fvRequest::getInstance()->hasRequestParameter("page")) {
                if (fvSite::$fvSession->is_set(fvRequest::getInstance()->getRequestParameter("requestURL")."/page")) {
                    fvRequest::getInstance()->putRequestParameter("page",
                        (int)fvSite::$fvSession->get(fvRequest::getInstance()->getRequestParameter("requestURL")."/page"));
                } 
            } else {
                fvSite::$fvSession->set(fvRequest::getInstance()->getRequestParameter("requestURL")."/page", 
                    fvRequest::getInstance()->getRequestParameter("page"));
            }
        } else {
            fvRequest::getInstance()->putRequestParameter("page", 0);
            fvSite::$fvSession->remove(fvRequest::getInstance()->getRequestParameter("requestURL")."/page");
        }
        
        if (is_array($filterArray)) {
            fvResponce::getInstance()->setHeader('filtered', true);
            if ($filterArray['_clear'] == "1") {
                fvSite::$fvSession->remove("$currentUrl/filter", $filterArray);
            } else {
                fvSite::$fvSession->set("$currentUrl/filter", $filterArray);
            }
        }
        return true;
     }
}
